﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_ViewMenu.cshtml";
}
<script src="/Content/After/js/jquery.min.js"></script>
<script>
    $(function () {
        page(1, 8);
    })
    function page(a, b) {

        $.ajax({
            type: 'post',
            url: '/AuthorInfo/FnshowAuthorInfo',
            data: { a: a, b: b },
            dataType: 'Json',
            success: function (mes) {
                var tr = new Array();
                var pager = new Array();
                var state = "";
                $(mes.PageList).each(function (i, obj) {
                    if (obj.AuthorState == 1) {
                        state = "启用";
                    }
                    else {
                        state = "禁用";
                    }
                    tr.push("<tr>");
                    tr.push("<td>" + obj.AuthorId + "</td><td>" + obj.AuthorName + "</td>");
                    tr.push("<td>" + obj.AuthorUrl + "</td><td>" + state + "</td>");
                    tr.push("<td><a href='#'  onclick='delAuthorInfo(" + obj.AuthorId + ",0)'>禁用</a></td>");
                    tr.push("<td><a href='#'  onclick='delAuthorInfo(" + obj.AuthorId + ",1)'>启用</a></td>");
                    tr.push("<td><a href='/AuthorInfo/updUserInfo/" + obj.AuthorId + " '>修改</a></td>");
                    tr.push("</tr>");
                    $("#AuthorInfo tbody").html(tr.join(""));

                })

                pager.push("<a href='#' onclick='page(1,8)'>首页</a>");

                if (mes.PageIndex > 1) {
                    pager.push("<a href='#'  onclick='page(" + (mes.PageIndex - 1) + ",8)'>上一页</a>");
                }
                else {
                    pager.push("<a href='#' >上一页</a>");
                }
                pager.push("<span>第" + mes.PageIndex + "页</span>");

                if (mes.PageIndex < mes.PageCount) {
                    pager.push("<a href='#'  onclick='page(" + (mes.PageIndex + 1) + ",8)'>下一页</a>");
                }
                else {
                    pager.push("<a href='#' >下一页</a>");
                }
                pager.push("<a href='#'  onclick='page(" + mes.PageCount + ",8)'>尾页</a>");

                $("#page").html(pager.join(""));

            }
        })
    }
    function delAuthorInfo(AuthorId, state)
        {
            $.ajax({
                type: 'post',
                url: '/AuthorInfo/FndelUserInfo',
                data: { AuthorId: AuthorId, state: state },
                dataType: 'Json',
                success: function (mes) {
                    if (mes>0) {
                        alert("状态已修改！");
                        location.href = "/AuthorInfo/Index";

                    }
                    else {
                        alert("修改失败！");
                    }
                }
            })

    }
 
</script>
<div>
  &nbsp;  &nbsp;  <a href="/AuthorInfo/addAuthorInfo">添加菜单</a>

    <table id="AuthorInfo">
        <thead>
            <tr>
                <td>编号</td>
                <td>名称</td>
                <td>路径</td>
                <td>状态</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>

        </tbody>
    </table>
    <div id="page"></div>
</div>